<!DOCTYPE html>
<html>
<body>

<?php
header("Location:http://127.0.0.1:5222/tieba.html");
$userid = ($_COOKIE["userid"]);
$username= ($_COOKIE["username"]);
$title=($_POST["title"]);
$content=($_POST["content"]);
$count="select postid from posts order by postid;";
echo "{$tilte}";
echo "<br>{$content}";
echo "<br>{$username}";
$mysqli = new mysqli("127.0.0.1", "root", "20155222", "lzj");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

echo "{$sql}";
if ($result = $mysqli->query($count)) {
	for($i=0;$i<$result->num_rows;$i++){
		$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
		if($i!=current($row)){
			$postid=$i;
			break;
		}
		next($result);
	}
	if($i==$result->num_rows)
		$postid=$i;
	$result->close();
}
$sql="insert into posts(postid,userid,username,title,content)values('{$postid}','{$userid}','{$username}','{$title}','{$content}');";
$mysqli->query($sql);

$mysqli->close();
?>

</body>
</html>
